(function (aopc) {
    aopc.addExpandPage(856, function (get) {
        const Common = get('UtilsCommon', 'Common');
        return {
            expandInit() {
                const left_view = this.getProperty('left_view');
                this.time_text = this.getViewProperty(left_view, 'time_text');
                this.date_text = this.getViewProperty(left_view, 'date_text');
                this.week_text = this.getViewProperty(left_view, 'week_text');
                this.meeting_room_name = this.getProperty('meeting_room_name');
                this.meetingServices = this.getProperty('MeetingSevices');

                setInterval(() => {
                    this.showTime();
                }, 1000 * 60);

                this.showTime();

                this.receiveFunctions.sendService = this.sendService.bind(this);
            },
            sendService() {
                this.refreshDataList();
            },
            setInit() {
                this.meeting_room_name.text = this.visitUser.MeetingRoomName;
            },
            getMeetingRoomId() {
                return { pathQuery: `?$orderby=Id&$filter=MeetingRoomId eq @MeetingRoomId&@MeetingRoomId=${this.visitUser.MeetingRoomId}` };
            },
            showTime() {
                const date = new Date();
                let hh = date.getHours();
                hh = hh < 10 ? `0${hh.toString()}` : hh.toString();
                let mm = date.getMinutes();
                mm = mm < 10 ? `0${mm.toString()}` : mm.toString();

                let month = (date.getMonth() + 1);
                let day = date.getDate();

                this.setValue(this.date_text, `${month}月${day}日`);
                this.setValue(this.time_text, hh + ":" + mm);
                this.setValue(this.week_text, Common.getWeek(date));
            },
            setValue(p, v) {
                p.value = v;
                p.setValue && p.setValue(v);
            },
            refreshDataList() {
                this.meetingServices.id = Common.createGuid();
                this.meetingServices.isCache = false;
                this.meetingServices.refreshOptions();
            },
            deleteService({ property }) {
                if (property.isLoading) return;
                this.confirm('确定要删除会议服务吗？', () => {
                    const { serviceInterface, data } = property;
                    const { serviceName, actionName } = serviceInterface;

                    const { ServiceId, RowVersion } = data;

                    const payload = { pathQuery: `(${ServiceId})?RowVersion=${RowVersion}` }

                    property.isLoading = true;
                    this.dispatchAction(serviceName, actionName, payload).then(res => {
                        property.isLoading = false;
                        if (res.isSuccess !== false) {
                            this.alertSuccess('删除成功！', () => {
                                this.refreshDataList();
                            });
                        }
                    });
                });
            },
            updateStatus({ property }) {
                if (property.isLoading) return;
                this.confirm('确定要发送处理收到信息吗？', () => {
                    const { serviceInterface, data } = property;
                    const { serviceName, actionName } = serviceInterface;

                    const { ServiceId, MeetingId, CreateUser, RowVersion } = data;

                    const entityData = {
                        HandlerStatus: 1
                    }

                    const payload = { MeetingService: entityData, pathQuery: `(${ServiceId})?RowVersion=${RowVersion}` }

                    property.isLoading = true;
                    this.dispatchAction(serviceName, actionName, payload).then(res => {
                        property.isLoading = false;
                        if (res.isSuccess !== false) {
                            this.webSocket.send('receiveService', {
                                CreateUser,
                                MeetingId
                            })
                            this.alertSuccess('发送成功', () => {
                                this.refreshDataList();
                            });
                        }
                    });
                });
            },
        }
    });
})(window.aopc);